import { reqGetUserInfo, reqLogout } from "@/api";
const state = {
  userInfo: {},
};
const mutations = {
  GETUSERINFO(state, data) {
    state.userInfo = data;
  },
  LOGOUT(state) {
    state.userInfo = {};
  },
};
const actions = {
  async getUserInfo({ commit }) {
    const data = await reqGetUserInfo();
    if (data.code === 200) commit("GETUSERINFO", data.data);
    else return Promise.reject("非法TOKEN,请重新登录!");
  },
  async logout({ commit }) {
    await reqLogout();
    localStorage.removeItem("TOKEN");
    commit("LOGOUT");
  },
};
const getters = {};
export default {
  state,
  mutations,
  actions,
  getters,
};
